#!/usr/bin/env python
# -*-coding:UTF-8-*-
# Author: chenzuoqing@126.com
# Create: 2018/8/2 17:17
# File  : serializers.py

"""
项目权限相关的序列化类
"""

from django.contrib.auth.models import Permission
from rest_framework import serializers

from permissions.models import Menu


class PermissionSerializer(serializers.ModelSerializer):

    perm_name = serializers.SerializerMethodField()

    class Meta:
        model = Permission
        fields = '__all__'

    @staticmethod
    def get_perm_name(instance):
        return ' '.join((instance.content_type.app_label, instance.content_type.model, instance.name))


class MenuSerializer(serializers.ModelSerializer):
    """
    前端左侧菜单序列化类
    """

    class Meta:
        model = Menu
        fields = ("id", "path", "icon", "title", "show", "parent")
